import config
from random import random
from utils import *

def register():
	return NudgeBack()

class NudgeBack:
	def __init__(self):
		self.type = 'passive'
		self.last = 0
		self.help = \
'''戳一戳响应：
	用法：无（自动）
	在感知到戳一戳时做出的反应。'''

	def run(self, gum, msg):
		if not msg['type'] == 'NudgeEvent' \
				or msg['fromId'] == config.utils.bot \
				or (msg['target'] != config.utils.bot and random() >= 0.1):
			return
		if msg['fromId'] == self.last:
			return
		self.last = msg['fromId']
		post('sendNudge', target = msg['fromId'],
			 subject = msg['subject']['id'], kind = msg['subject']['kind'])